package handler

import (
	"fmt"
	"zinxtcp/default/encoder"
	"zinxtcp/default/message"
	"zinxtcp/handler"
	"zinxtcp/ziface"
)

type HelloZinxHandler2 struct {
	handler.BaseHandler
}

//HelloZinxRouter Handle
func (this *HelloZinxHandler2) Handle(request ziface.ISockPack) error {
	fmt.Println("Call HelloZinxRouter Handle")
	//先读取客户端的数据，再回写ping...ping...ping
	fmt.Println("recv from client : msgId=", request.GetMsgType(), ", data=", string(request.GetData()))
	packHeader := message.NewPackHeader(1003)
	data := []byte("Hello Zinx Router V0.10")
	sentData, err := encoder.Pack(packHeader, data)
	if err != nil {
		return err
	}
	err = request.GetConnection().SendData(sentData)
	if err != nil {
		return err
	}
	return nil
}
